package com.mzj.eagle.thread;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.mzj.eagle.redis.MigrationSyc;

public class RedisSycThread implements Runnable {
	
	private static final Logger LOG = Logger.getLogger(RedisSycThread.class);
	
	private String fromRedisUrl;
	
	private String toRedisUrl;
	
	public enum ThreadName {
		From("From"),To("To");
	    private String name ;
	    private ThreadName( String name){
	        this.name = name ;
	    }
	    public String getName() {
	        return name;
	    }
	    
	}
	
	public void run() {
		if(StringUtils.isEmpty(fromRedisUrl)) {
			throw new RuntimeException(Thread.currentThread().getName() +" the redis(From) url is null!");
		}
		if(StringUtils.isEmpty(toRedisUrl)) {
			throw new RuntimeException(Thread.currentThread().getName() +" the redis(To) url is null!");
		}
		try {
			MigrationSyc.sync(fromRedisUrl, toRedisUrl);
		} catch (Exception e) {
			LOG.error(Thread.currentThread().getName() +":"+ e.getMessage(),e);
			throw new RuntimeException(e);
		}
	}



	public RedisSycThread(String fromRedisUrl, String toRedisUrl) {
		super();
		this.fromRedisUrl = fromRedisUrl;
		this.toRedisUrl = toRedisUrl;
	}

	public RedisSycThread() {
		super();
	}  
}
